package reivew;

import java.util.Scanner;

public class Dingcanxitong {
    //有问题
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int max = 10;
        String[] xm = new String[max]; // 保存订餐人名称
        String[] cd = {"红烧带鱼", "鱼香肉丝", "时令鲜蔬"}; // 菜品名
        double[] dj = {38.0, 20.0, 10.0}; // 菜品单价
        int[] sj = new int[max]; // 保存送餐时间
        int[] dzs = new int[max]; // 保存点赞数
        String[] dz = new String[max]; // 保存送餐地址
        int[] zt = new int[max]; // 保存订单状态： 0：已预订 1：已完成
        double[] ze = new double[max]; // 保存订单的总金额
        while (true) {
            System.out.println("欢迎使用“吃货联盟订餐系统”");
            System.out.println("*************************");
            System.out.println("1.我要订餐");
            System.out.println("2.查看餐袋");
            System.out.println("3.签收订单");
            System.out.println("4.删除订单");
            System.out.println("5.我要点赞");
            System.out.println("6.退出系统");
            System.out.println("**************************");
            System.out.println("请选择：");
            int a = 0;
            while (true) {
                a = input.nextInt();
                if (a > 0 && a <= 6) {
                    break;
                }
                System.out.println("错误，重输：");

            }
            switch (a) {
                case 1: {
                    System.out.println("***我要订餐***");
                    int i = 0;
                    for (; i < xm.length; i++) {
                        if (xm[i] == null) {
                            System.out.print("请输入订餐人姓名：");
                            xm[i] = input.next();
                            break;
                        }
                    }
                    System.out.println("序号" + "   菜名  " + "   单价   " + "点赞数 ");
                    for (int j = 0; j < cd.length; j++) {
                        System.out.println((j + 1) + "   " + cd[j] + "   " + dj[j] + "元" + "   " + dzs[j]);
                    }
                    System.out.print("请选择您要点的菜品：");
                    int b = input.nextInt();
                    while (b < 1 || b > 3) {
                        System.out.println("输入错误，请重新输入：");
                        b = input.nextInt();
                        i = b - 1;////
                    }
                    System.out.print("请选择您需要的份数：");
                    int c = input.nextInt();
                    while (c < 1) {
                        System.out.println("输入错误，请重新输入：");
                        c = input.nextInt();
                    }
                    System.out.println("请输入送餐时间(送餐时间是10点到20点间整点送餐)：");
                    int s = input.nextInt();
                    while (s < 10 || s > 20) {
                        System.out.println("送餐时间超过送餐时间范围，请重新输入：");
                        s = input.nextInt();
                    }
                    sj[i] = s;
                    System.out.println("请输入送餐地址：");
                    dz[i] = input.next();
                    double cf = (dj[b-1]) * c;
                    double scf = cf < 50 ? 5.0 : 0;
                    ze[i] = cf + scf;
                    System.out.println("订餐成功！");
                    System.out.print("您订的是：" + cd[i] + c + "份" + "送餐时间：" + sj[i] + "点餐费：" +
                            cf + "元,送餐费：" + scf + "元，总计：" + ze[i] + "元");
                    break;
                }
                case 2: {
                    System.out.println("***查看餐袋***");
                    System.out.println("序号" + "  姓名" + "   菜单" + "      总价" + "  送餐时间" + "  送餐地址" + " 订单状态");
                    for (int i = 0; i < xm.length; i++) {
                        if (xm[i] != null) {
                            System.out.println((i + 1) + "     " + xm[i] + "    " + cd[i] + "    " + ze[i] + "元    " + sj[i] +
                                    "点    " + dz[i] + "  " + zt[i]);
                        }
                    }
                    break;
                }
                case 3: {
                    System.out.println("***签收订单***");
                    System.out.println("请选择需要签收订单的序号：");
                    int b = input.nextInt();//签收序号
                    for (int i = 0; i < xm.length; i++) {
                        if (xm[i] != null && zt[i] == 0 && b == i + 1) {
                            zt[i] = 1;
                            System.out.println("订单签收成功！");
                        } else if (xm[i] != null && zt[i] == 1 && b == i + 1) {
                            System.out.println("订单已经签收过！");
                        } else if (xm[i] == null && b == i + 1) {
                            System.out.println("未查询到有效订单");
                        }
                    }
                    break;
                }
                case 4: {
                    System.out.println("***删除订单***");
                    System.out.println("请输入需要删除的订单序号：");
                    int s = input.nextInt();
                    for (int i = 0; i < xm.length; i++) {
                        if (xm[i] != null && zt[i] == 1 && s == i + 1) {
                            for (int j = s - 1; j < xm.length - 1; j++) {
                                xm[j] = xm[j + 1];
                                sj[j] = sj[j + 1];
                                dz[j] = dz[j + 1];
                                zt[j] = zt[j + 1];
                                ze[j] = ze[j + 1];
                            }
                            System.out.println("删除成功！");
                            xm[xm.length - 1] = null;
                            sj[xm.length - 1] = 0;
                            dz[xm.length - 1] = null;
                            zt[xm.length - 1] = 0;
                            ze[xm.length - 1] = 0;
                        } else if (xm[i] != null && zt[i] == 0 && s == i + 1) {
                            System.out.println("订单未签收，无法删除！");
                        } else if (xm[i] == null && zt[i] == 0 && s == i + 1) {
                            System.out.println("未找到有效订单！");
                        }
                    }
                    break;
                }
                case 5: {
                    System.out.println("***我要点赞***");
                    System.out.println("序号" + "   菜名  " + "   单价   " + "点赞数 ");
                    for (int j = 0; j < cd.length; j++) {
                        System.out.println((j + 1) + "   " + cd[j] + "   " + dj[j] + "元" + "   " + dzs[j]);
                    }
                    System.out.print("请选择您要点赞的菜品：");
                    int z = input.nextInt();
                    if (z <= xm.length + 1 && z > 0) {
                        dzs[z - 1]++;
                    } else {
                        System.out.println("输入序号不在菜单内！");
                    }
                    break;
                }
                case 6:
                    System.out.println("谢谢使用，欢迎下次光临！");
                    return;
            }
            System.out.println();
            System.out.println("输入任意键返回主菜单");
            String b = input.next();
        }
    }
}
